import { routes } from "@/routes/list";
import { transformRoute } from "@/utils/common";
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { useLocation } from "react-router-dom";

const useChilRoute = () => {
    const temp = transformRoute(routes[0].children);
    const location = useLocation();
    const store = useSelector((state: any) => state.setting);
    const list = location.pathname.split("/").filter(el => el);
    const [res, setRes] = useState<any>([]);
    useEffect(() => {
        setRes(store.layout == 'mix' ? temp.find((el: any) => el.key === list[0])?.children : []);
    }, [store.layout, location.pathname])

    return { res }
}

export default useChilRoute;